from django.db import models

# Create your models here.

class Area(models.Model):
    area_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    location = models.TextField(blank=True, null=True)

    def __str__(self):
        return self.name

    class Meta:
        managed = True
        db_table = 'area'
        verbose_name = '区域'
        verbose_name_plural = '区域'


class Audience(models.Model):
    audience_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50, null=True, blank=True)
    audience_type = models.CharField(max_length=20, null=True, blank=True, default='普通观众')
    phone = models.CharField(max_length=20, null=True, blank=True)

    def __str__(self):
        return self.name or f"观众{self.audience_id}"

    class Meta:
        managed = True
        db_table = 'audience'
        verbose_name = '观众'
        verbose_name_plural = '观众'


class Exhibitor(models.Model):
    exhibitor_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100, unique=True)
    country = models.CharField(max_length=50, null=True, blank=True)
    contact_person = models.CharField(max_length=50, null=True, blank=True)
    contact_phone = models.CharField(max_length=20, null=True, blank=True)
    area = models.ForeignKey(Area, on_delete=models.CASCADE, db_column='area_id')
    num_exhibits = models.IntegerField(default=0)

    def __str__(self):
        return self.name

    class Meta:
        managed = True
        db_table = 'exhibitor'
        verbose_name = '参展商'
        verbose_name_plural = '参展商'


class Exhibit(models.Model):
    exhibit_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100)
    category = models.CharField(max_length=50, default='未分类')
    description = models.CharField(max_length=255, null=True, blank=True)
    exhibitor = models.ForeignKey(Exhibitor, on_delete=models.CASCADE, db_column='exhibitor_id')

    def __str__(self):
        return self.name

    class Meta:
        managed = True
        db_table = 'exhibit'
        verbose_name = '展品'
        verbose_name_plural = '展品'


class ExhibitInfo(models.Model):
    exhibit_name = models.CharField(max_length=100, primary_key=True)
    category = models.CharField(max_length=50, default='未分类')
    area_name = models.CharField(max_length=50, default='未知区域')

    def __str__(self):
        return self.exhibit_name

    class Meta:
        managed = True
        db_table = 'exhibitinfo'
        verbose_name = '展品信息'
        verbose_name_plural = '展品信息'


class Schedule(models.Model):
    event_id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=100)
    event_time = models.DateTimeField()
    area = models.ForeignKey(Area, on_delete=models.CASCADE, db_column='area_id')
    exhibitor = models.ForeignKey(Exhibitor, on_delete=models.SET_NULL, null=True, blank=True)
    exhibit = models.ForeignKey(Exhibit, on_delete=models.SET_NULL, null=True, blank=True, db_column='exhibit_id')

    def __str__(self):
        return self.title

    class Meta:
        managed = True
        db_table = 'schedule'
        verbose_name = '活动日程'
        verbose_name_plural = '活动日程'


class Attendance(models.Model):
    audience = models.ForeignKey(Audience, on_delete=models.CASCADE, db_column='audience_id')
    show = models.ForeignKey(Schedule, on_delete=models.CASCADE, db_column='event_id')
    seatinfo = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'attendance'
        unique_together = (('audience', 'show'),)
        verbose_name = '参与记录'
        verbose_name_plural = '参与记录'


class EventDetails(models.Model):
    id = models.AutoField(primary_key=True)
    event_title = models.CharField(max_length=100)
    event_time = models.DateTimeField()
    area_name = models.CharField(max_length=50, default='未知区域')
    exhibitor_name = models.CharField(max_length=100, default='未知参展商')
    exhibit_name = models.CharField(max_length=100, default='未知展品')

    def __str__(self):
        return self.event_title

    class Meta:
        managed = True
        db_table = 'eventdetails'
        verbose_name = '活动详情'
        verbose_name_plural = '活动详情'


# Django认证系统相关模型
class AuthGroup(models.Model):
    name = models.CharField(unique=True, max_length=150)

    class Meta:
        managed = False
        db_table = 'auth_group'


class AuthGroupPermissions(models.Model):
    id = models.BigAutoField(primary_key=True)
    group = models.ForeignKey(AuthGroup, models.DO_NOTHING)
    permission = models.ForeignKey('AuthPermission', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'auth_group_permissions'
        unique_together = (('group', 'permission'),)


class AuthPermission(models.Model):
    name = models.CharField(max_length=255)
    content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING)
    codename = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = 'auth_permission'
        unique_together = (('content_type', 'codename'),)


class AuthUser(models.Model):
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=150)
    first_name = models.CharField(max_length=150)
    last_name = models.CharField(max_length=150)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'auth_user'


class AuthUserGroups(models.Model):
    id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey(AuthUser, models.DO_NOTHING)
    group = models.ForeignKey(AuthGroup, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'auth_user_groups'
        unique_together = (('user', 'group'),)


class AuthUserUserPermissions(models.Model):
    id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey(AuthUser, models.DO_NOTHING)
    permission = models.ForeignKey(AuthPermission, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'auth_user_user_permissions'
        unique_together = (('user', 'permission'),)


class DjangoAdminLog(models.Model):
    action_time = models.DateTimeField()
    object_id = models.TextField(blank=True, null=True)
    object_repr = models.CharField(max_length=200)
    action_flag = models.PositiveSmallIntegerField()
    change_message = models.TextField()
    content_type = models.ForeignKey('DjangoContentType', models.DO_NOTHING, blank=True, null=True)
    user = models.ForeignKey(AuthUser, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'django_admin_log'


class DjangoContentType(models.Model):
    app_label = models.CharField(max_length=100)
    model = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = 'django_content_type'
        unique_together = (('app_label', 'model'),)


class DjangoMigrations(models.Model):
    id = models.BigAutoField(primary_key=True)
    app = models.CharField(max_length=255)
    name = models.CharField(max_length=255)
    applied = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'django_migrations'


class DjangoSession(models.Model):
    session_key = models.CharField(primary_key=True, max_length=40)
    session_data = models.TextField()
    expire_date = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'django_session'


class Audienceinfo(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    tel = models.CharField(max_length=255, blank=True, null=True)
    note = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'audienceinfo'


class Equipment(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    model = models.CharField(max_length=255, blank=True, null=True)
    performer = models.ForeignKey('Performer', models.DO_NOTHING, blank=True, null=True)
    info = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'equipment'


class News(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255)
    content = models.TextField(blank=True, null=True)
    date = models.DateField(blank=True, null=True)
    image = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'news'


class Show(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    performer = models.ForeignKey('Performer', models.DO_NOTHING, blank=True, null=True)
    area = models.ForeignKey(Area, models.DO_NOTHING, blank=True, null=True)
    time = models.DateTimeField(blank=True, null=True)
    ticket = models.IntegerField(blank=True, null=True)
    info = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'show'


class Performer(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    nationality = models.CharField(max_length=255, blank=True, null=True)
    info = models.TextField(blank=True, null=True)
    image = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'performer'
